package com.lry.rpc.starter.extend;

import com.lry.rpc.starter.annotation.EnableRpcConfig;
import com.lry.rpc.starter.config.RpcConfigConfiguration;
import com.lry.rpc.starter.util.AnnotatedBeanDefinitionRegistryUtils;
import com.lry.rpc.starter.util.RpcBeanUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;


public class RpcConfigConfigurationRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableRpcConfig.class.getName()));
        boolean multiple = attributes.getBoolean("multiple");
        AnnotatedBeanDefinitionRegistryUtils.registerBeans(registry, new Class[]{RpcConfigConfiguration.Single.class});
        if (multiple) {
            AnnotatedBeanDefinitionRegistryUtils.registerBeans(registry, new Class[]{RpcConfigConfiguration.Multiple.class});
        }

//        RpcBeanUtils.registerCommonBeans(registry);
    }
}
